diff options
Diffstat (limited to 'src/routes/projects/[projectId]/routine/[routineId]/+page.server.ts')
| -rw-r--r-- | src/routes/projects/[projectId]/routine/[routineId]/+page.server.ts | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/routes/projects/[projectId]/routine/[routineId]/+page.server.ts b/src/routes/projects/[projectId]/routine/[routineId]/+page.server.ts index 83bac3c..f2b6551 100644 --- a/src/routes/projects/[projectId]/routine/[routineId]/+page.server.ts +++ b/src/routes/projects/[projectId]/routine/[routineId]/+page.server.ts @@ -31,21 +31,31 @@ export const load: PageServerLoad = async ({ params }) => { } const routine = await loadCurrent(routineId); - if (!routine || routine.archived || routine.projectId !== projectId) { + if (!routine || routine.projectId !== projectId) { throw error(404, 'Routine introuvable'); } const completions = await loadCompletions(routineId); + // An archived routine is frozen at its archive instant: state and chart + // stop there instead of now. + const at = routine.archivedAt ? Date.parse(routine.archivedAt) : Date.now(); return { project: { id: project.id, name: project.name }, routine, completions, - state: computeRoutineState(routine, completions, Date.now()), + state: computeRoutineState(routine, completions, at), }; }; export const actions: Actions = { edit: async ({ request, params }) => { + const current = await loadCurrent(numericId(params.routineId)); + if (!current) { + return fail(400, { error: 'Routine introuvable' }); + } + if (current.archived) { + return fail(400, { error: 'Routine archivée' }); + } const data = await request.formData(); const name = parseFormString(data.get('name')); if (!name) { @@ -65,6 +75,13 @@ export const actions: Actions = { }, complete: async ({ request, params }) => { + const current = await loadCurrent(numericId(params.routineId)); + if (!current) { + return fail(400, { error: 'Routine introuvable' }); + } + if (current.archived) { + return fail(400, { error: 'Routine archivée' }); + } const data = await request.formData(); try { await complete( |
